//
//  SXTBaseViewController.m
//  8.18项目
//
//  Created by ma c on 16/8/20.
//  Copyright © 2016年 zhang. All rights reserved.
//

#import "SXTBaseViewController.h"
#import "SXTAFNetworkingClient.h"
#import <SVProgressHUD.h>
#import "UIView+Toast.h"
@interface SXTBaseViewController ()

@end

@implementation SXTBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

-(void)POSTRequestURL:(NSString *)url param:(NSDictionary *)param isSuccess:(requestSuccessBlock)returnSuccess isError:(requestErrorBlock)returnError{

    [SVProgressHUD show];
    [SXTAFNetworkingClient POSTRequest:url param:param isSuccess:^(id responseObject) {
        [SVProgressHUD dismiss];
        if (returnSuccess) {
            returnSuccess(responseObject);
        }
    } isError:^(NSError *error) {
        [SVProgressHUD dismiss];
        [self showTostInView:@"请检查网络设置"];
        if(returnError)
        {
            returnError(error);
        
        }
    }];

}
- (void)GETRequestURL:(NSString *)url param:(NSDictionary *)param isSuccess:(requestSuccessBlock)returnSuccess isError:(requestErrorBlock)returnError{
    [SVProgressHUD show];
    [SXTAFNetworkingClient GETRequest:url
                                param:param
                            isSuccess:^(id responseObject) {
                                [SVProgressHUD dismiss];
                                if (returnSuccess) {
                                    returnSuccess(responseObject);
                                }
                            } isError:^(NSError *error) {
                                [SVProgressHUD dismiss];
                                [self showTostInView:@"请检查网络设置"];
                                if (returnError) {
                                    returnError(error);
                                }
                            }];
}

- (void)showTostInView:(NSString *)tost{
    [self.view makeToast:tost duration:1.5 position:@"center"];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
